package com.shop.admin.dto;

import com.shop.admin.entity.CouponBatch;
import com.shop.admin.entity.CouponRule;
import com.shop.admin.interfaces.couponBatchDTOConvert;
import com.shop.admin.interfaces.couponRuleDTOConvert;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class CouponRuleDTO {

    /**
     * 主键
     */
    private Integer ruleId;
    /**
     * 使用门槛
     */
    private Double threshold;
    /**
     * 制券类型 1满送(集合） 2 满折 3满减
     */
    private Integer couponType;
    /**
     * 券使用范围 1全场 2类别 3商品(集合）
     */
    private Integer couponRange;
    /**
     * 是否限制发券数量
     */
    private Integer isLimitCount;
    /**
     * 总发放数量
     */
    private Integer limitCount;
    /**
     * 每个用户可以领取的数量
     */
    private Integer receiveCount;
    /**
     * 是否是互斥卷
     */
    private Integer isMutex;
    /**
     * 领取开始时间
     */
    private Date receiveStarted;
    /**
     * 领取结束时间
     */
    private Date receiveEnd;
    /**
     * 使用开始时间
     */
    private Date useStated;
    /**
     * 使用结束时间
     */
    private Date useEnd;
    /**
     * 批次名称
     */
    private String batchName;
    /**
     * 券名称
     */
    private String couponName;
    /**
     * 已发放数量
     */
    private Integer assignCount;
    /**
     * 已使用数量
     */
    private Integer usedCount;
    /**
     * 制券类型所需关键字段 1满送时为商品id 2 满折为折扣 3满减为实减金额
     */
    private List<String> couponTypeNeed;
    /**
     * 券使用范围所需关键字段  2类别时为类别id 3商品时间为商品id
     */
    private Integer couponRangeNeed;

    public CouponRule convertToRule() {
        CouponRuleInputCouponRuleDTOConvert couponRuleInputDTOConvert = new CouponRuleInputCouponRuleDTOConvert();
        CouponRule couponRule = couponRuleInputDTOConvert.convertForRule(this);
        return couponRule;
    }

    private static class CouponRuleInputCouponRuleDTOConvert implements couponRuleDTOConvert<CouponRuleDTO,CouponRule> {
        @Override
        public CouponRule convertForRule(CouponRuleDTO couponRuleDTO) {
            CouponRule couponRule = new CouponRule();
            BeanUtils.copyProperties(couponRuleDTO,couponRule);
            return couponRule;
        }
    }

    public CouponBatch convertToBatch() {
        CouponBatchInputCouponRuleDTOConvert couponBatchInputCouponRuleDTOConvert = new CouponBatchInputCouponRuleDTOConvert();
        CouponBatch couponBatch = couponBatchInputCouponRuleDTOConvert.convertForBatch(this);
        return couponBatch;
    }

    private static class CouponBatchInputCouponRuleDTOConvert implements couponBatchDTOConvert<CouponRuleDTO, CouponBatch> {
        @Override
        public CouponBatch convertForBatch(CouponRuleDTO couponRuleDTO) {
            CouponBatch couponBatch = new CouponBatch();
            BeanUtils.copyProperties(couponRuleDTO,couponBatch);
            return couponBatch;
        }
    }
}
